//
//  BRCacheManager.m
//  BrezzeSaaS
//
//  Created by IOS on 2021/8/31.
//  Copyright © 2021 Brezze GWG. All rights reserved.
//

#import "BRCacheManager.h"
#import <YYCache/YYCache.h>

static NSString *cacheKey = @"BRCacheManager";

@interface BRCacheManager ()
{
    YYCache *_yyCache;
}

@end

@implementation BRCacheManager

+ (BRCacheManager *)share {
    static BRCacheManager *man = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        man = [[BRCacheManager alloc] init];
    });
    return man;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        _yyCache = [[YYCache alloc] initWithName:cacheKey];
    }
    return self;
}

- (void)save:(id<NSCoding>)obj tableName:(NSString *)key {
    
    [_yyCache setObject:obj forKey:key];
}

- (id<NSCoding>)getValue:(NSString *)key {
    return [_yyCache objectForKey:key];
}

- (void)removeObj:(NSString *)key {
    if ([self hasValueForKey:key]) {
        [_yyCache removeObjectForKey:key];
    }
    
}

- (BOOL)hasValueForKey:(NSString *)key {
    return [_yyCache containsObjectForKey:key];
}


@end
